package com.qidianit.task.controller;

import com.qidianit.task.pojo.Task;
import com.qidianit.task.service.TaskService;
import com.qidianit.task.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author hitsune
 * @Company kafu chino
 * @Description
 * @Time 2024/9/10 17:02
 */

@RestController
@CrossOrigin
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    @GetMapping("/list")
    public QdResult taskList(String projectId,Long parentId){
        return taskService.list(projectId, parentId);
    }
    @GetMapping("/get")
    public QdResult selectTaskById(Long taskId){
        return taskService.selectById(taskId);
    }
    @PostMapping("/save")
    public QdResult save(@RequestBody Task task){
        return taskService.saveTask(task);
    };
    @PutMapping("/update/{taskId}")
    public void update(@PathVariable Long taskId,@RequestBody Task task){
        task.setTaskId(taskId);
         taskService.replaceTask(task);
    }
    @PutMapping("/delete/{taskId}")
    public void deleteTask(@PathVariable Long taskId){
        taskService.deleteByTaskId(taskId);
    }
}
